package com.example.baselibrary.rx;

import com.example.baselibrary.utils.ZLog;

import io.reactivex.Observable;
import io.reactivex.functions.Function;
import retrofit2.Response;

/**
 * by zqq on 2018/6/12.
 */

public class BaseResponseFunc<V, T> implements Function<Response<V>, Observable<V>> {

    @Override
    public Observable<V> apply(Response<V> tResponse) throws Exception {
        if (tResponse.code() == 200) {
            ZLog.e(tResponse.toString());

            return Observable.just(tResponse.body());
        } else {
            ZLog.e(tResponse.toString());

            return Observable.error(new Exception("服务器错误，请联系管理员"));
        }
    }

}
